#include<iostream>
#include<algorithm>
using namespace std;
int num[105];
bool cmp(int a,int b){
	int sum_a = 0,sum_b = 0,aa = a,bb = b;
	while(a){
		sum_a += a % 10;
		a /= 10; 
	}
	while(b){
		sum_b += b % 10;
		b /= 10;
	}
	if(sum_a == sum_b){
		return aa < bb;
	}else{
		return sum_a < sum_b;
	}
	
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&num[i]);
	}
	sort(num,num+n,cmp);
	for(int i=0;i<n;i++){
		if(i != n-1){
			printf("%d ",num[i]);
		}else{
			printf("%d\n",num[i]);
		}
	}
	return 0;
} 
